<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2019/12/27
 * Time: 9:08
 */
namespace util;
class StringUtil
{
    protected static $instance = null;
    private function __construct()
    {
    }
    private function __clone()
    {
    }

    public static function instance(){
        if(empty(self::$instance)){
            self::$instance = new static();
        }
        return self::$instance;
    }
    /**
     * 字符串转换为数组，主要用于把分隔符调整到第二个参数
     * @param  string $str  要分割的字符串
     * @param  string $glue 分割符
     * @return array
     */
    function strToArr(string $str, string $glue = ','):array
    {

        return explode($glue, $str);
    }

    /**
     * 字符串替换
     */
    function sr($str = '', $target = '', $content = '')
    {

        return str_replace($target, $content, $str);
    }

    /**
     * 字符串前缀验证
     */
    function str_prefix($str, $prefix)
    {

        return strpos($str, $prefix) === 0 ? true : false;
    }
}